#include "TriangleApp.h"

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>

#include <stdexcept>
#include <array>
#include <cassert>

const float PI_2 = glm::two_pi<float>();
const float PI = glm::pi<float>();

TriangleApp::TriangleApp()
{
	loadGameObjects();

}

TriangleApp::~TriangleApp()
{
}

void TriangleApp::run()
{
	SimpleRenderSystem simpleRenderSystem{ lvDevice, lvRenderer.getSwapChainRendPass() };
	while (!lvWindow.shouldClose())
	{
		glfwPollEvents();
		auto commandBuffer = lvRenderer.beginFrame();
		lvRenderer.beginSwapChainRenderPass(commandBuffer);

		simpleRenderSystem.renderGameObject(commandBuffer, gameObjects);

		lvRenderer.endSwapChainRenderPass(commandBuffer);
		lvRenderer.endFrame();

	}
	vkDeviceWaitIdle(lvDevice.device());
}

void TriangleApp::loadGameObjects()
{
	std::vector<LvModel::Vertex> vertices{
		{{0.0f, -0.5f}, {1.0f, 0.0f, 0.0f}},
		{{0.5f, 0.5f}, {0.0f, 1.0f, 0.0f}},
		{{-0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}}
	};
	auto lvModel = std::make_shared<LvModel>(lvDevice, vertices);

	auto triangle = LvGameObject::createGameObject();
	triangle.model = lvModel;
	triangle.color = { 0.1f, 0.8f, 0.1f };
	triangle.trnsform2d.translation = { 0.2f, 0.0f };
	triangle.trnsform2d.scale = { 2.0f, 0.5f };
	triangle.trnsform2d.rotation = 0.0f;

	gameObjects.push_back(std::move(triangle));
}





